package xyz.yuelai.blog.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.page.PageMethod;

import xyz.yuelai.blog.dao.IArticleCategoryDAO;
import xyz.yuelai.blog.entity.ArticleCategory;
import xyz.yuelai.blog.service.IArticleCategoryService;
import xyz.yuelai.blog.util.PageInfoUtil;



@Service("articleCategoryService")
public class ArticleCategoryServiceImpl implements IArticleCategoryService {

	@Autowired
	private IArticleCategoryDAO articleCategoryDAO;

	@Override
	public void saveArticleCategory(ArticleCategory articleCategory) {
		articleCategoryDAO.saveArticleCategory(articleCategory);
	}

	@Override
	public void deleteArticleCategory(Map<String, Object> conditionMap) {
		articleCategoryDAO.deleteArticleCategory(conditionMap);
	}

	@Override
	public void updateArticleCategory(ArticleCategory articleCategory) {
		articleCategoryDAO.updateArticleCategory(articleCategory);
	}

	@Override
	public ArticleCategory getArticleCategory(Map<String, Object> conditionMap) {
		return articleCategoryDAO.getArticleCategory(conditionMap);
	}

	@Override
	public List<ArticleCategory> getArticleCategoryList(PageInfoUtil pageInfoUtil, Map<String, Object> conditionMap) {
		if (pageInfoUtil != null) {
			Page<ArticleCategory> page = PageMethod.startPage(pageInfoUtil.getCurrentPage(),
					pageInfoUtil.getPageSize());
			List<ArticleCategory> articleCategoryList = articleCategoryDAO.getArticleCategoryList(conditionMap);
			pageInfoUtil.setTotalRecord((int) page.getTotal());
			return articleCategoryList;
		}
		return articleCategoryDAO.getArticleCategoryList(conditionMap);
	}
}
